//文件指定编译编码UTF-8
#pragma execution_character_set("utf-8")

/**
*    @file:    widget.cpp
*    @brief:
*    @author:  sanshi522@163.com
*    @date:    2025-03-10  14:46
*/
#include "widget.h"
#include "ui_widget.h"
#include <QFileDialog>
#include <QFileIconProvider>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->pushButton->setEnabled(false);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_toolButton_clicked()
{
    QString filePath = QFileDialog::getOpenFileName(this,"选择程序","","*.exe");
    if(!filePath.isEmpty()){
        ui->lineEdit->setText(filePath);
        QFileInfo fileInfo(filePath);
        QFileIconProvider iconProvider;
        QIcon icon = iconProvider.icon(fileInfo);

        // 获取所有可用尺寸
            QList<QSize> sizes = icon.availableSizes();
            qDebug() << "Available sizes:";
            for (const QSize &size : sizes) {
                qDebug() << size;
            }

        if (!icon.isNull())
        {
            QPixmap pixmap = icon.pixmap(QSize(32, 32)); // 调整尺寸以适应需求
            ui->label_pix->setPixmap(pixmap);
            ui->pushButton->setEnabled(true);
        }
        else
        {
            ui->label_pix->clear();
            ui->pushButton->setEnabled(false);
        }
    }
}

void Widget::on_pushButton_clicked()
{
    QString filePath = QFileDialog::getSaveFileName(this,"选择保存路径","","*.ico");
    if(!filePath.isEmpty()){
       ui->label_pix->pixmap()->save(filePath, "ICO"); // 保存为.ico文件
    }
}
